Private Sub Command1_Click()
' Calculate the geometric center of all text items of a document

    Dim appRef As New Photoshop.Application
    Dim selectedObjects As Variant
    Dim objectBounds As Variant
    Dim objectCenter As Variant
    Dim textItemRef As Photoshop.TextItem
    Dim theTextType As Photoshop.PsTextType
    
    theTextType = psParagraphText
    If (appRef.Documents.Count > 0) Then
        Set docRef = appRef.ActiveDocument
        For Each artLayerRef In docRef.ArtLayers
            If (artLayerRef.HasText) Then
                docRef.ActiveLayer = artLayerRef
                
                ' must set the text kind to paragraph because you can only get the bounds of paragraph text.
                artLayerRef.TextItem.Kind = theTextType
                            
                objectBounds = artLayerRef.TextItem.Bounds
                objectCenter = GetItemCenter(objectBounds)
                MsgBox ("Center of Text Item  x: " & objectCenter(0) & ",  y :" & objectCenter(1))
            End If
        Next
    End If
End Sub
' The following lines define the function
Function GetItemCenter(sourceBounds As Variant) As Variant
    Dim left As Single
    Dim top As Single
    Dim right As Single
    Dim bottom As Single
    Dim xCenter As Single
    Dim yCenter As Single
    left = sourceBounds(0)
    top = sourceBounds(1)
    right = sourceBounds(2)
    bottom = sourceBounds(3)
    xCenter = (left + right) / 2
    yCenter = (top + bottom) / 2
    GetItemCenter = Array(xCenter, yCenter)
End Function
